#ifndef LOADIMAGEBLL_H
#define LOADIMAGEBLL_H

#include <QObject>
#include <QPixmap>
#include <QEvent>
#include "loadimagebllcallback.h"
#include "EZTally/EZTallyArray.h"
#include "EZTally/EZTallyDictionary.h"
#include <QMutex>

class LoadImageFinishEvent;
class LoadImageObj;
class LoadImageBLLEvent;

class LoadImageBLL : public QObject
{
    Q_OBJECT
public:
    explicit LoadImageBLL(QObject *parent = 0);
    ~LoadImageBLL();
    static LoadImageBLL* shareLoadImageBll();
    virtual bool event(QEvent * event);
signals:
//    void loadImageFinish(int error,QString &path,QPixmap &pixmap);
public :
    void loadImageFromDisk(const QString &path,LoadImageBllCallBack *callBack);
    // 只要在 对像 delete 的时候 remove 就行了
    void removeLoad(LoadImageBllCallBack *callBack);
private:
    QMutex _callBacksMutex;
    //现在只做简单的记住当前对像还可以callback,不作过多的区分
    QList<LoadImageBllCallBack*> _callBacks;
//    EZTally::EZTallyDictionary<int,EZTally::EZTallyArray<> >
private:
    LoadImageObj *_loadObj;


public :

};

class LoadImageObj : public QObject
{
public:
    LoadImageObj(QObject *parent,LoadImageBLL* manager);
    ~LoadImageObj();
    virtual bool	event(QEvent * event);
private:
    LoadImageBLL *_manager;
    QThread *_thread;
};

class LoadImageBLLEvent : public QEvent
{
public:
    LoadImageBLLEvent(QEvent::Type type);
    ~LoadImageBLLEvent();
    QString path() const;
    void setPath(const QString &path);

public:
    QString _path;
    LoadImageBllCallBack *_callBack;

};

class LoadImageFinishEvent : public QEvent
{
public:
    LoadImageFinishEvent(QEvent::Type type);
    ~LoadImageFinishEvent();
public:
    QString _path;
    int _error;
    QPixmap _pixmap;
private:
    friend class LoadImageBLL;
    friend class LoadImageObj;
    LoadImageBllCallBack *_callBack;

};

#endif // LOADIMAGEBLL_H
